package vip.meeet.jdk.files;

import org.junit.jupiter.api.Test;

import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

public class StoryOcr {

    @Test
    public void readTxt() throws IOException {
        File dir = new File("C:\\soft\\office\\hwang\\IMAGE\\故事技巧—叙事性非虚构文学写作指南");
        File[] files = dir.listFiles(new FileFilter() {
            @Override
            public boolean accept(File pathname) {
//                System.out.println(pathname.getName());
                if (pathname.getName().toLowerCase().endsWith(".txt"))
                    return true;
                return false;
            }
        });
        StringBuffer sb = new StringBuffer();
        for(File file : files){
//            System.out.println(file.getName());
            Path path = Paths.get(file.toURI());
            List<String> strings = Files.readAllLines(path, Charset.forName("gb2312"));
            for(String string:strings){
//                System.out.println(string);
                sb.append(string.replaceAll("获取更多资源请登录尘宇下载站www. cydown. cn","")).append("\n");
            }
        }

        Path path = Paths.get("G:\\doc\\me\\story_skill.md");
        Files.write(path,sb.toString().getBytes());
    }
}
